<template>
  <div>
    <TopTitle :texttitle="'账号注册'" :gourl="'/login'"></TopTitle>

    <van-form @submit="onSubmit" class="from-vant">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
        class="vant-from-information"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
        class="vant-from-information"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit" color="#21b97a" class="vant-from-btn"
          >注 册</van-button
        >
      </div>
    </van-form>
    <router-link to="/login" class="goRegiste"
      >已有账号？去登录</router-link
    >
  </div>
</template>

<script>
import { registe } from '@/api/Interface'
import TopTitle from '@/components/TopTitle.vue'
export default {
  name: 'registe',
    components:{
    TopTitle
  },
  data() {
    return {
      color: '#21b97a',
      username: '',
      password: '',
    }
  },
  methods: {
    async  onSubmit(values) {
      console.log('submit', values)
      const res = await registe(values)
      if(res.description === "创建成功"){
          this.$toast.success(res.description)
          this.$router.push('/login')
      }else{
        this.$toast.fail(res.description)
      }
    },
  },
}
</script>

<style scoped lang="less">
.van-nav-bar__title {
  color: #fff;
}
.goRegiste {
  color: #666;
  font-size: 14px;
  margin: 30px auto;
  display: block;
  text-align: center;
}
.from-vant {
  margin-top: 30px;
  .vant-from-information {
    height: 60px;
    width: 345px;
    font-size: 17px;
    margin: 10px auto;
    padding: 0 0 0 5px;
    line-height: 50px;
    border-bottom: 1px solid rgba(0, 0, 0, 0);
  }
  .vant-from-btn{
    width: 345px;
    height: 50px;
    font-size: 18px;
    line-height: 50px;
  }
}
</style>
